﻿#include <iostream>
class T {

    static int count1;//不能直接访问
    inline static int cou1{};
public:
    inline static int cou{ 150 };//C++17新用法，直接定义变量
    const static int cou2{ 100 };//加入const关键字能直接定义
    static int count;//静态变量需要放到外面单独定义，储存大小并不算入类的大小中
    int hp;

    T() {
        cou1++;
    }
    int GetCount() {
        return cou1;
    }

    ~T() {
        cou1--;
    }

};
int T::count1 = 100;
int T::count = 100;//定义static变量值需要放在外面
void test();
int main()
{
    T t1, t2, t3, t4;
    t1.count++;
    std::cout << t2.count << std::endl;//101
    std::cout << t3.count << std::endl;//101，值一样
    std::cout << &t2.count << std::endl;//00007FF7D544C000
    std::cout << &t3.count << std::endl;//00007FF7D544C000，内存地址一样

    std::cout << t2.cou << std::endl;//150
    std::cout << t2.cou2 << std::endl;//100
    std::cout << sizeof(T) << std::endl;//4

    //T::hp = 100;//报错，hp不是静态变量
    T::count = 350;
    T t5;
    std::cout << t5.count << std::endl;//350
    std::cout << T::count << std::endl;//350

    std::cout << t5.GetCount() << std::endl;//5
}
void test() {
    T t1, t2, t3;
}
